//
// Matrix.cpp for  in /home/herpec_j/Dropbox/Projets/raytracer-2016/Sources/Maths/
//
// Made by Jonathan
// Login   <ledey_l@epitech.net>
//
// Started on  Sun Sep 22 11:25:18 2013 Jonathan
// Last update Sun Sep 22 16:27:51 2013 Jonathan
//

#include	"Maths/Matrix.hpp"

namespace	Maths
{
  Matrix::Matrix(void)
  {
    for (unsigned short x = 0; x < 4; ++x)
      {
	for (unsigned short y = 0; y < 4; ++y)
	  {
	    if (x == y)
	      {
		mMatrix[x][y] = 1.0f;
	      }
	    else
	      {
		mMatrix[x][y] = 0.0f;
	      }
	  }
      }
  }

  Matrix::Matrix(Matrix const &rOther)
  {
    for (unsigned short x = 0; x < 4; ++x)
      {
	for (unsigned short y = 0; y < 4; ++y)
	  {
	    mMatrix[x][y] = rOther.mMatrix[x][y];
	  }
      }
  }

  Matrix	&Matrix::operator=(Matrix const &rOther)
  {
    if (this != &rOther)
      {
	for (unsigned short x = 0; x < 4; ++x)
	  {
	    for (unsigned short y = 0; y < 4; ++y)
	      {
		mMatrix[x][y] = rOther.mMatrix[x][y];
	      }
	  }
      }
    return (*this);
  }

  Matrix	Matrix::operator*(Matrix const &rOther) const
  {
    Matrix	product;
    long double	sum;

    for (unsigned short y = 0; y < 4; ++y)
      {
	for (unsigned short x = 0; x < 4; ++x)
	  {
	    sum = 0.0f;
	    for (unsigned short j = 0; j < 4; ++j)
	      {
		sum += mMatrix[x][j] * rOther.mMatrix[j][y];
	      }
	    product.mMatrix[x][y] = sum;
	  }
      }
    return (product);
  }

  Matrix	Matrix::operator/(long double rNumber) const
  {
    Matrix	result;

    for (unsigned short x = 0; x < 4; ++x)
      {
	for (unsigned short y = 0; y < 4; ++y)
	  {
	    result.mMatrix[x][y] = mMatrix[x][y] / rNumber;
	  }
      }
    return (result);
  }

  void		Matrix::SetIdentity(void)
  {
    for (unsigned short x = 0; x < 4; ++x)
      {
	for (unsigned short y = 0; y < 4; ++y)
	  {
	    if (x == y)
	      {
		mMatrix[x][y] = 1.0f;
	      }
	    else
	      {
		mMatrix[x][y] = 0.0f;
	      }
	  }
      }
  }

  long double	**Matrix::GetMatrix(void) const
  {
    return ((long double **) mMatrix);
  }

  Matrix::~Matrix(void)
  {
    return;
  }
};
